import { WsConnection } from "tsrpc";
import { ecs } from "../../../core/ecs/ECS";
import { ECSEntity } from "../../../core/ecs/ECSEntity";
import { Room } from "../Room";
import { ServiceType } from "../../../tsrpc/shared/protocols/RoomServiceProto";

@ecs.register('RoomJoin')
export class RoomJoinComp extends ecs.Comp {
    uId:number = null!;
    conn:WsConnection<ServiceType> = null!;
    reset(): void {
        
    }
}

export class RoomJoinSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
    entityEnter(entity: Room): void {
        const joinUId = entity.get(RoomJoinComp).uId;
        const conn = entity.get(RoomJoinComp).conn;

        entity.addRole(conn, joinUId);
        //广播
        entity.broadcastMsg("msg/RoleJoin", {
            role: {},
            time: new Date().getTime(),
        })
    }
    filter(): ecs.IMatcher {
        return ecs.allOf(RoomJoinComp);
    }
}